import os
import yaml


class YamlReader:

	def __init__(self, yaml_file_path="../conf/config.yml"):

		if os.path.exists(yaml_file_path):
			self.yaml_file_path = yaml_file_path
		else:
			raise FileNotFoundError("配置文件未找到!")
		self._data = None

	@property
	def data(self):
		with open(self.yaml_file_path, 'rb') as f:
			self._data = list(yaml.safe_load_all(f))
		return self._data

	def get(self, key, index=0):
		return self.data[index].get(key)


if	__name__ == "__main__":
	print(YamlReader().get("mysql"))